<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .light{
            width: 200px;
            height: 200px;
            background-color: black;
        }
        .lightOff{
            width: 200px;
            height: 200px;
            background-color: yellow;
        }
    </style>
</head>

<body>
    <div id="div">
       <button @click = "onChange">{{isOn?'关灯':'开灯'}}</button>
       <div :class="isOn?'lightOff':'light'"></div>

       <!-- <div style="background-color:yellow"></div> -->
       

    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>

        var app = Vue.createApp({

            data: function () {
                return {
                    age: 0,
                    isOn:false
                }
            },
            // 存放一些方法，供事件调用
            methods: {
                onClick(e) {
                    // 阻止冒泡
                    // e.stopPropagation();
                    this.num++;
                },
                onAdd(n1,n2){
                    e.preventDefault();
                    
                    this.num = n1+n2
                },
                onChange(){
                    this.isOn = !this.isOn 
                }
            },


        }).mount('#div');

    </script>
</body>

</html>